package io.github.maojian.sort;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Auther: jian.mao
 * @Date: 2022-07-04 09:04
 * @Description: https://leetcode.cn/problems/minimum-absolute-difference/
 */
public class Q1200 {
    public List<List<Integer>> minimumAbsDifference(int[] arr) {
        Arrays.sort(arr);
        int length = arr.length;
        int minVal = Integer.MAX_VALUE;
        List<List<Integer>> rtnList = new ArrayList<>();
        for (int i = 0; i < length - 1; i++) {
            int curVal = arr[i + 1] - arr[i];
            if (minVal > curVal) {
                minVal = curVal;
                rtnList.clear();
                List<Integer> curList = new ArrayList<>();
                curList.add(arr[i]);
                curList.add(arr[i + 1]);
                rtnList.add(curList);
            } else if (minVal == curVal) {
                List<Integer> curList = new ArrayList<>();
                curList.add(arr[i]);
                curList.add(arr[i + 1]);
                rtnList.add(curList);
            }
        }
        return rtnList;
    }

    @Test
    public void test() {
        int[] arr = new int[]{3, 8, -10, 23, 19, -4, -14, 27};
        minimumAbsDifference(arr).stream().forEach(System.out::println);
    }
}
